const axios = require("axios");
const fs = require("fs");
const cheerio = require("cheerio")
const {
    html
} = require("./Huawei-index.js")

function loadHW() {

    let $ = cheerio.load(html);

    // 图片.css-1dbjc4n img"
    let top4 = $(".css-1dbjc4n img");


    console.log(top4.length);
    let arr = [];
    for (var i = 0; i < top4.length; i++) {
        arr.push({
            // unit: unit.eq(i).html(),
            // price: price.eq(i).html(),
            src: top4.eq(i).attr("src"),
            // title: title.eq(i).html(),
            // goodsClassify : goodsClassify.eq(i).html(),
            // titleEng : titleEng.eq(i).html()
        })
    }

    // 把爬取到的数据转存
    fs.writeFile("./static/data/index/1.json", JSON.stringify(arr), err => {
        if (err) throw err;
        console.log("hw爬取成功");
    })
}

loadHW();